import { IPSControlAction } from './ipscontrol-action';
import { IPSControlNavContext } from './ipscontrol-nav-context';
import { IPSControlNavParam } from './ipscontrol-nav-param';
import { IPSMDAjaxControl } from './ipsmdajax-control';
import { IPSMDControl2 } from './ipsmdcontrol2';
import { PSAjaxControlContainerImpl } from './psajax-control-container-impl';
import { IPSDEDataExport } from '../dataentity/dataexport/ipsdedata-export';
import { IPSDEDataImport } from '../dataentity/dataimport/ipsdedata-import';

export class PSMDAjaxControlContainerImpl extends PSAjaxControlContainerImpl implements IPSMDAjaxControl, IPSMDControl2 {
  protected createpscontrolaction: IPSControlAction | null = null;

  getCreatePSControlAction(): IPSControlAction | null {
    if (this.createpscontrolaction != null) return this.createpscontrolaction;
    const value = this.M.getCreatePSControlAction;
    if (value == null) {
      return null;
    }
    this.createpscontrolaction = this.getPSControlHandlerMust().findPSControlHandlerAction(value);
    return this.createpscontrolaction;
  }

  get createPSControlAction(): IPSControlAction | null {
    return this.getCreatePSControlAction();
  }

  getCreatePSControlActionMust(): IPSControlAction {
    const value = this.getCreatePSControlAction();
    if (value == null) {
      throw new Error('未指定建立数据行为');
    }
    return value;
  }

  protected fetchpscontrolaction: IPSControlAction | null = null;

  getFetchPSControlAction(): IPSControlAction | null {
    if (this.fetchpscontrolaction != null) return this.fetchpscontrolaction;
    const value = this.M.getFetchPSControlAction;
    if (value == null) {
      return null;
    }
    this.fetchpscontrolaction = this.getPSControlHandlerMust().findPSControlHandlerAction(value);
    return this.fetchpscontrolaction;
  }

  get fetchPSControlAction(): IPSControlAction | null {
    return this.getFetchPSControlAction();
  }

  getFetchPSControlActionMust(): IPSControlAction {
    const value = this.getFetchPSControlAction();
    if (value == null) {
      throw new Error('未指定查询数据行为');
    }
    return value;
  }

  protected getdraftfrompscontrolaction: IPSControlAction | null = null;

  getGetDraftFromPSControlAction(): IPSControlAction | null {
    if (this.getdraftfrompscontrolaction != null) return this.getdraftfrompscontrolaction;
    const value = this.M.getGetDraftFromPSControlAction;
    if (value == null) {
      return null;
    }
    this.getdraftfrompscontrolaction = this.getPSControlHandlerMust().findPSControlHandlerAction(value);
    return this.getdraftfrompscontrolaction;
  }

  get getDraftFromPSControlAction(): IPSControlAction | null {
    return this.getGetDraftFromPSControlAction();
  }

  getGetDraftFromPSControlActionMust(): IPSControlAction {
    const value = this.getGetDraftFromPSControlAction();
    if (value == null) {
      throw new Error('未指定获取草稿数据行为（拷贝）');
    }
    return value;
  }

  protected getdraftpscontrolaction: IPSControlAction | null = null;

  getGetDraftPSControlAction(): IPSControlAction | null {
    if (this.getdraftpscontrolaction != null) return this.getdraftpscontrolaction;
    const value = this.M.getGetDraftPSControlAction;
    if (value == null) {
      return null;
    }
    this.getdraftpscontrolaction = this.getPSControlHandlerMust().findPSControlHandlerAction(value);
    return this.getdraftpscontrolaction;
  }

  get getDraftPSControlAction(): IPSControlAction | null {
    return this.getGetDraftPSControlAction();
  }

  getGetDraftPSControlActionMust(): IPSControlAction {
    const value = this.getGetDraftPSControlAction();
    if (value == null) {
      throw new Error('未指定获取草稿数据行为');
    }
    return value;
  }

  protected getpscontrolaction: IPSControlAction | null = null;

  getGetPSControlAction(): IPSControlAction | null {
    if (this.getpscontrolaction != null) return this.getpscontrolaction;
    const value = this.M.getGetPSControlAction;
    if (value == null) {
      return null;
    }
    this.getpscontrolaction = this.getPSControlHandlerMust().findPSControlHandlerAction(value);
    return this.getpscontrolaction;
  }

  get getPSControlAction(): IPSControlAction | null {
    return this.getGetPSControlAction();
  }

  getGetPSControlActionMust(): IPSControlAction {
    const value = this.getGetPSControlAction();
    if (value == null) {
      throw new Error('未指定获取数据行为');
    }
    return value;
  }

  protected pscontrolnavcontexts: IPSControlNavContext[] | null = null;

  getPSControlNavContexts(): IPSControlNavContext[] | null {
    if (this.pscontrolnavcontexts == null) {
      this.pscontrolnavcontexts = this.fillChildListModel(this.M.getPSControlNavContexts, 'control.IPSControlNavContext') as IPSControlNavContext[];
    }
    return this.pscontrolnavcontexts;
  }

  get psControlNavContexts(): IPSControlNavContext[] | null {
    return this.getPSControlNavContexts();
  }

  findPSControlNavContext(objKey: any): IPSControlNavContext | null {
    return this.getPSModel5('control.IPSControlNavContext', this.getPSControlNavContexts(), objKey) as IPSControlNavContext;
  }

  protected pscontrolnavparams: IPSControlNavParam[] | null = null;

  getPSControlNavParams(): IPSControlNavParam[] | null {
    if (this.pscontrolnavparams == null) {
      this.pscontrolnavparams = this.fillChildListModel(this.M.getPSControlNavParams, 'control.IPSControlNavParam') as IPSControlNavParam[];
    }
    return this.pscontrolnavparams;
  }

  get psControlNavParams(): IPSControlNavParam[] | null {
    return this.getPSControlNavParams();
  }

  findPSControlNavParam(objKey: any): IPSControlNavParam | null {
    return this.getPSModel5('control.IPSControlNavParam', this.getPSControlNavParams(), objKey) as IPSControlNavParam;
  }

  protected psdedataexport: IPSDEDataExport | null = null;

  getPSDEDataExport(): IPSDEDataExport | null {
    if (this.psdedataexport != null) return this.psdedataexport;
    const value = this.M.getPSDEDataExport;
    if (value == null) {
      return null;
    }
    this.psdedataexport = this.getPSAppDataEntityMust().findPSAppDEDataExport(value);
    return this.psdedataexport;
  }

  get psDEDataExport(): IPSDEDataExport | null {
    return this.getPSDEDataExport();
  }

  getPSDEDataExportMust(): IPSDEDataExport {
    const value = this.getPSDEDataExport();
    if (value == null) {
      throw new Error('未指定数据导出对象');
    }
    return value;
  }

  protected psdedataimport: IPSDEDataImport | null = null;

  getPSDEDataImport(): IPSDEDataImport | null {
    if (this.psdedataimport != null) return this.psdedataimport;
    const value = this.M.getPSDEDataImport;
    if (value == null) {
      return null;
    }
    this.psdedataimport = this.getPSAppDataEntityMust().findPSAppDEDataImport(value);
    return this.psdedataimport;
  }

  get psDEDataImport(): IPSDEDataImport | null {
    return this.getPSDEDataImport();
  }

  getPSDEDataImportMust(): IPSDEDataImport {
    const value = this.getPSDEDataImport();
    if (value == null) {
      throw new Error('未指定数据导入对象');
    }
    return value;
  }

  protected removepscontrolaction: IPSControlAction | null = null;

  getRemovePSControlAction(): IPSControlAction | null {
    if (this.removepscontrolaction != null) return this.removepscontrolaction;
    const value = this.M.getRemovePSControlAction;
    if (value == null) {
      return null;
    }
    this.removepscontrolaction = this.getPSControlHandlerMust().findPSControlHandlerAction(value);
    return this.removepscontrolaction;
  }

  get removePSControlAction(): IPSControlAction | null {
    return this.getRemovePSControlAction();
  }

  getRemovePSControlActionMust(): IPSControlAction {
    const value = this.getRemovePSControlAction();
    if (value == null) {
      throw new Error('未指定删除数据行为');
    }
    return value;
  }

  protected updatepscontrolaction: IPSControlAction | null = null;

  getUpdatePSControlAction(): IPSControlAction | null {
    if (this.updatepscontrolaction != null) return this.updatepscontrolaction;
    const value = this.M.getUpdatePSControlAction;
    if (value == null) {
      return null;
    }
    this.updatepscontrolaction = this.getPSControlHandlerMust().findPSControlHandlerAction(value);
    return this.updatepscontrolaction;
  }

  get updatePSControlAction(): IPSControlAction | null {
    return this.getUpdatePSControlAction();
  }

  getUpdatePSControlActionMust(): IPSControlAction {
    const value = this.getUpdatePSControlAction();
    if (value == null) {
      throw new Error('未指定更新数据行为');
    }
    return value;
  }

  get hasWFDataItems(): boolean {
    return this.M.hasWFDataItems;
  }

  getHasWFDataItems(): boolean {
    return this.M.hasWFDataItems;
  }

  get readOnly(): boolean {
    return this.M.readOnly != null ? this.M.readOnly : false;
  }

  get cls(): string {
    return 'PSMDAjaxControlContainerImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.IPSMDAjaxControl' || cls == 'control.IPSMDControl' || cls == 'control.IPSMDControl2') return true;
    return super.instanceof(cls);
  }
}
